﻿using System;
using System.Collections.Generic;
using System.Linq;
using Framework.Exceptions.RepositoryExceptions;
using Interfaces.Repositories;
using Interfaces.RepositoryModels.ExternalModels.FilterModels;

namespace SQLRepositories.FilterRepositories
{
    public class CompanyFilterRepository : EntityBaseRepository<CompanyFilterModel>, IFilterRepository<CompanyFilterModel>
    {
        public CompanyFilterRepository(IDBEconomicInformationServiceContext context) 
            : base(context)
        {}


        public void Create(CompanyFilterModel item)
        {
            Context.CompanyFilters.Add(item);
            Context.SaveChanges();
        }

        public CompanyFilterModel GetById(Guid id)
        {
            return Context.CompanyFilters.FirstOrDefault(x => x.Id.Equals(id));
        }

        public void Delete(Guid id)
        {
           var removedItem = Context.CompanyFilters.FirstOrDefault(x => x.Id.Equals(id));
           if(removedItem == null)
               throw new EntityNotFoundException("CompanyFilter");
            Context.CompanyFilters.Remove(removedItem);
            Context.SaveChanges();
        }

        public void Delete(CompanyFilterModel item)
        {
            Context.CompanyFilters.Remove(item);
            Context.SaveChanges();
        }

        public IEnumerable<CompanyFilterModel> GetAll()
        {
            return Context.CompanyFilters;
        }
    }
}
